package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = OrderSettingService.class)
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingDao orderSettingDao;

    //文件上传
    public void add(List<OrderSetting> orderSettingList) {

        if (orderSettingList != null && orderSettingList.size() > 0) {
            //遍历获取OrderSetting对象
            for (OrderSetting orderSetting : orderSettingList) {
                //查询OrderSetting对象中的日期是否存在
                long count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
                if (count > 0) {
                    //文件已经上传
                    orderSettingDao.editNumberByOrderDate(orderSetting);
                } else {
                    //文件未上传
                    orderSettingDao.add(orderSetting);
                }
            }
        }


    }

    //页面显示预约数据
    public List<Map> getOrderSettingByMonth(String date) {
        return orderSettingDao.getOrderSettingByMonth(date);
    }


}
